﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.SqlClient;
using AVCare.LMS.LocalData;
using AVCare.LMS.Models;

namespace AVCare.LMS.LocalData
{
    public class DailyHelper
    {
        private string _userID;
        public DailyHelper(string userID)
        {
            _userID = userID;
        }

        LMSEntities entities = new LMSEntities();

        /// <summary>
        /// 获取日程
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public IEnumerable<Daily> GetDaily(DateTime date)
        {
            try
            {
                var x = (from b in entities.Dailies where b.Date.Year == date.Year && b.Date.Month == date.Month && b.Date.Day == date.Day && b.UID.Equals(_userID) select b);

                return x.ToList();
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 获取日程
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public IEnumerable<Daily> GetDaily()
        {
            return GetDaily(DateTime.Now);
        }

        /// <summary>
        /// 获取当天日程数量
        /// </summary>
        /// <returns></returns>
        public int GetDailyCount(DateTime date)
        {
            var x = entities.Dailies.Count(b => b.Date.Year == date.Year && b.Date.Month == date.Month && b.Date.Day == date.Day && b.UID.Equals(_userID));

            return x;
        }




        IEnumerable<DailyDetail> GetDetail(Guid dailyID)
        {
            var query = (from b in entities.DailyDetails where b.DailyID == dailyID select b);

            return query.ToList();
        }


    }
}
